<!DOCTYPE html>
<html lang="zh-CN">
<meta charset="utf-8" />
<head>
<title>编辑监测信息 <?php echo $this->config->item('title');?></title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet"
	href="<?php echo base_url()?>public/css/bootstrap.min.css">
<link rel="stylesheet"
	href="<?php echo base_url()?>public/css/style.css">
<link rel="stylesheet"
	href="<?php echo base_url()?>public/css/select2/select2.css">

<link rel="stylesheet"
	href="<?php echo base_url()?>public/css/select2/select2-bootstrap.css">
</head>
<body>
	<script src="<?php echo base_url()?>public/js/jquery-2.0.2.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap.min.js"></script>
	<script src="<?php echo base_url()?>public/js/bootstrap-confirm.js"></script>
	<script src='<?php echo base_url()?>public/js/bootbox.min.js'></script>
	<script src='<?php echo base_url()?>public/js/jquery.form.js'></script>
	<script src='<?php echo base_url()?>public/js/select2.min.js'></script>
	<script src='<?php echo base_url()?>public/js/select2_locale_zh-CN.js'></script>
	<script src='<?php echo base_url()?>public/js/ssi_common.js'></script>
	<script type="text/javascript">
	jQuery(function($) {

		var change_mp =false;

		$("#change_monitor_pic").click(function(){
			if (change_mp==false) {
				change_mp =true;
				$(this).text("取消修改");
				$(".monitor_pic").show();
			}else{
				change_mp =false;
				$(this).text("变更监控照片");
				file = $("#monitor_pic");  
				file.after(file.clone());   
				file.remove();  
				$(".monitor_pic").hide();
			}
		});
		
		
		$("#media_id").select2({
		    placeholder: "请输入媒体位置或媒体编号",
		    minimumInputLength: 4,
		    ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
		        url: "<?php echo base_url()?>/index.php/media_media_manage/search_media",
		        dataType:'json', 
		        data: function (term, page) {
		            return {
		                q: term
		            };
		        },
		        results: function (data, page) {
		            return {results: data.media};
		        }
		    },
		  
		    formatResult: formatAsText, // omitted for brevity, see the source of this page
		    formatSelection: format,  // omitted for brevity, see the source of this page
		    escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
		});
		function format(item) {
		    return item.id;
		}
		function formatAsText(media){
			var itemFmt ="<div style='display:inline;'>"+media.id+"</div><div style='float:right;color:#4F4F4F;display:inline'>"+media.location+"</div>"; 
		     return itemFmt;  
		}  


		$("#brand").select2({
		    placeholder: "搜索品牌",
		    minimumInputLength: 1,
		    ajax: {
		        url: "<?php echo base_url()?>index.php/sys_brand_manage/search_brand",
		        dataType:'json', 
		        data: function (term, page) {
		            return {
		                keyword: term
		            };
		        },
		        results: function (data, page) {
		            return {results: data.brand};
		        }
		    },
		    formatResult: formatBrandText,
		    formatSelection: formatBrand,  
		    escapeMarkup: function (m) { return m; } 
		});
		function formatBrand(brand) {
		    return brand.name;
		}
		function formatBrandText(brand){
			var itemFmt =brand.name; 
		     return itemFmt;  
		}  
		

		$(".bigdrop").find(".select2-chosen").text("<?php echo $monitor_info['media_id']?>");
		$(".bigdrop1").find(".select2-chosen").text("<?php echo $monitor_info['brand_name']?>");
		$("#parent1").select2();
		$("#parent2").select2();
		$('#main_from').ajaxForm({
			dataType:  'json',
			beforeSubmit:  showRequest,
			success:   processJson
		});
		function showRequest(formData, jqForm, options) {
		}
		function processJson(data) {
			if (data.result==false) {
				bootbox.alert(data.message, function() {
				});
				$('button[type="button"]').removeClass('disabled');
			}else{
				window.location.href=data.redirect_url;
			}
		}
	});
	</script>
	<div role="navigation" class="navbar navbar-inverse navbar-fixed-top">
		<div class="container">
			<div class="navbar-header">
				<a class="navbar-brand">SSI后台管理系统</a>
			</div>
			<div class="collapse navbar-collapse navbar-right">
				<ul class="nav navbar-nav">
					<li><a href="<?php echo base_url()?>" class="navbar-link">首页</a></li>
					<li><a
						href="<?php echo base_url()."index.php/common_login_user_set"?>"
						class="navbar-link">超级管理员</a></li>
					<li><a
						href="<?php echo base_url()?>index.php/common_login_manage/logout"
						class="navbar-link">退出</a></li>
				</ul>
			</div>
		</div>
	</div>
	<div class="container">
		<div class="row">
			<div class="col-xs-3">
				<?php echo $user_menu?>
			</div>
			<div class="col-md-9">
				<div class="panel panel-default">
					<div class="panel-heading">编辑监测信息</div>
					<div class="panel-body">
						<form method="post" enctype="multipart/form-data" id="main_from"
							action="<?php echo base_url()."index.php"?>/media_monitor_manage/update_monitor"
							class="form-horizontal">
							<div id="env_name" class="form-group">
								<label for="env_name" class="control-label col-sm-3">监测媒体</label>
								<div class="col-sm-5">
									<input id="media_id" class="bigdrop form-control"
										name="media_id" value="<?php echo $monitor_info['media_id']?>"
										style="width: 100%;" />
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div class="form-group">
								<label for="brand" class="control-label col-sm-3">品牌</label>
								<div class="col-sm-5">
									<input id="brand" class="bigdrop1 form-control" name="brand"
										value="<?php echo $monitor_info['brand']?>"
										style="width: 100%" />
								</div>
							</div>
							<div id="env_name" class="form-group">
								<label for="product_name" class="control-label col-sm-3">产品名称</label>
								<div class="col-sm-5">
									<input id="product_name" type="text" name="product_name"
										value="<?php echo $monitor_info['product_name']?>" required
										class="form-control">
								</div>
								<span class='help-block'>必填</span>
							</div>
							<div id="Parents" class="form-group">
								<label for="parent1" class="control-label col-sm-3">选择行业/品类</label>
								<div id="parents" class="col-sm-5">
									<select id="parent1" name="industry"
										onchange="onParent1Changed()" class="form-control"
										style="width: 100%">
										<option value="">请选择</option>
										<?php
										
if ($industry_list != null) {
											foreach ( $industry_list as $industry ) {
												?>
													<option value="<?php echo $industry['industry_id']?>"
											<?php echo $industry['industry_id']==$monitor_info['industry']?'selected="selected" ':'';?>><?php echo $industry['industry_name']?></option>
												<?php
											}
										}
										?>
									</select> <select id="parent2" name="industry_category"
										class="form-control" style="width: 100%">
										<option value="">请选择</option>
										<?php
										
if ($industry_category_list != null) {
											foreach ( $industry_category_list as $industry_category ) {
												?>
													<option
											value="<?php echo $industry_category['industry_id']?>"
											<?php echo $industry_category['industry_id']==$monitor_info['industry_category']?'selected="selected" ':'';?>><?php echo $industry_category['industry_name']?></option>
												<?php
											}
										}
										?>
									</select>
								</div>
								<span class='help-block'>必选</span>
							</div>
							<div class="form-group">
								<label for="monitor_pic" class="control-label col-sm-3">监测照片</label>
								<div class="col-sm-5">
									<?php if ($monitor_info['monitor_pic']) {?>
									<img
										src="<?php echo $this->config->item("ssi_file_url").$monitor_info['monitor_pic']?>"
										class="form_img" />
									<?php
									
} else {
										echo "还没有上传任何监测照片";
									}
									?>
									<br /> <a href="javascript:void()" id="change_monitor_pic">变更监测照片</a>
									<br /> <span class="monitor_pic" style="display: none;"> <input
										type="file" id="monitor_pic" name="monitor_pic1"
										class="form-control">
									</span>
								</div>
							</div>
							<input type="hidden" name="monitor_pic"
								value="<?php echo $monitor_info['monitor_pic']?>" /> <input
								type="hidden" name="monitor_id"
								value="<?php echo $monitor_info['monitor_id']?>" />
							<div class="form-group">
								<div class="col-sm-offset-3 col-sm-10">
									<button type="button"
										onclick='from_check_login($("#main_from"),"<?php echo base_url()?>")'
										class="btn btn-primary">编辑</button>
									<a href="javascript:void()" onclick='history.back()'>返回</a>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>
	</div>
	<script>
	$(function($) {
	 $("form").submit(function(e){
	  checkRegion();
	  var errors = $('.form-group.has-error');
	  if (errors.length > 0) {
	   e.preventDefault();
	   return;
	  }
	  $('button[type="button"]').addClass('disabled');
	 });
	});	
</script>
	<script>
	function onParent1Changed(){
		var parent1 = $("#parent1");
		var index = $("#parent1").get(0).selectedIndex;
		$("#parent2").select2("destroy");
		$("#parent2").remove();
		if (index == 0) {
			return;
		}
		var parentid = parent1.val();
		$.getJSON("<?php echo base_url()."index.php/sys_industry_manage/get_industrys"?>", { industry_id: parentid }, 
			function(json){
			$("#parents").append("<select style='width:100%;' id='parent2' name='industry_category' class='form-control' ></select>");
			var parent2 = $("#parent2");
			for(var i = 0, len = json.length; i<len; ++i){
				var category = json[i];
				parent2.append("<option value=" + category.industry_id + ">" + category.industry_name + "</option>");
			}
			parent2.select2();
		});
	}
</script>
	<div class="back-to" id="toolBackTop">
		<a title="返回顶部" onclick="window.scrollTo(0,0);return false;"
			href="#top" class="back-top"> 返回顶部</a> <a title="返回底部"
			onclick="window.scrollTo(0,document.body.scrollHeight);return false;"
			href="#bottom" class="back-bottom"> 返回底部</a>
	</div>
</body>
</html>
